#
# @lc app=leetcode.cn id=239 lang=python3
#
# [239] 滑动窗口最大值
#
from typing import List
# @lc code=start
class Solution:
    def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
        sum = 0
        ans = - float('inf')
        for i in range(k):
            sum += nums[i]
        ans = max(sum, ans)
        l = 0
        r = k-1
        n = len(nums)
        while r < n - 1:
            sum -= nums[l]
            l += 1
            r += 1 
            sum += nums[r]
            ans = max(sum, ans)
        return ans


# @lc code=end

